<?php
/**
 * 产品类
 * @author chenlisong E-mail:chenlisong1021@163.com 
 * @version 创建时间：2016年10月24日 上午11:58:32 
 * 类说明
 */
class SchoolAction extends BaseAction{
	
	public function index(){
		echo $this->err("非法操作！");
	}
	
	/**
	 * 获取所有学校
	 */
	public function getAllSchool(){
		$School = M("School");
		$where['flag'] = 1;
		if(S('S_SCHOOL')){//启用缓存
			$SchoolData = S('S_SCHOOL');
		}else{
			$field = "id,province,city,area,name";
			$SchoolData = $School->where($where)->order('seq asc')->field($field)->select();
			S('S_SCHOOL',$SchoolData,86400);//每天更新一次缓存，销量数据一天一更新
		}
		echo $this->suc($SchoolData, 0);
	}

	/**
	 * 获取所有学校区域
	 */
	public function searchSchool(){
		$School = M("School");
		$param = $this->param;
		$where['flag'] = 1;
		$where['name'] = array('like','%'.$param['keyword'].'%');
		$field = "id,province,city,area,name";
		$SchoolData = $School->where($where)->order('seq asc')->field($field)->select();
		echo $this->suc($SchoolData, 0);
	}

	/*
	 * 获取有超市的宿舍楼
	 */
	public function getSchoolfloor(){
		$shopModel = M("SchoolFloor");
		$param = $this->param;
		$where['school_id'] = $param['school_id'];
		$where['flag'] = 1;
		$field = "floor_num";
		$shopData = $shopModel->where($where)->field($field)->select();
		echo $this->suc($shopData, 0);
	}
	/**
	 * 获取学校区块和第一个区块的超市
	 */

	public function getSchoolArea(){
		$schoolAreaModel = M("SchoolAreas");
		$shopModel = M("Shop");
		$param = $this->param;
		$where['flag'] = 1;
		$where['status'] = 1;
		$where['school_id'] = $param['school_id'];
		$field = "id,area_name";
		$schoolAreaData = $schoolAreaModel->where($where)->order('seq asc')->field($field)->select();
		$shop_where['school_area_id'] = $schoolAreaData[0]['id'];
		$shop_where['flag'] = 1;
		$shop_field = "id,user_id,name,school_name,floor_num,status,logo,is_super,school_area_id";
		$shopData = $shopModel->where($shop_where)->field($shop_field)->select();
		if(empty($shopData)){
			$shopData = array();
		}
		echo $this->suc(array("school_area_list"=>$schoolAreaData,"first_school_area_shop"=>$shopData), 0);
	}
}